#
# Makefile
#

CC	= $(CROSS)gcc
AR	= $(CROSS)ar
RANLIB = $(CROSS)ranlib

RM	= /bin/rm

LIBAIF  = libappif.a
LIBCIF  = libhlpif.a
LIBSIF	= libsockif.a
TESTP   = test
CTESTP	= rvstest
STATP   = #rstat
STESTP	= sif
MTESTP	= multi
TESTP4	= test4
TEST5_L = test5_local
TEST5_R = test5_remote

#TARGET	= libappif.a

DCCLIB	=

SRCS = \
	    rvs_socket.c \
	    rvs_msg.c \
	    rvs_api_sock.c \
        rvs_helpif.c

CSRCS = \
	    rvs_msg.c \
	    rvs_api_sock.c \
        rvs_helpif.c

SSRCS = \
	    rsi_sockif.c \
	    rsi_apisock.c \
	    rsi_tcpipif.c \
	    rsi_callback.c

SMSRC	= rvs_msg.c
SMOBJ	= rsi_msg.o

RRSRC	= rrutil.c
RROBJ	= rrutil.o
RRDEFS	= -DUSE_THREAD=1

TSRC	= stattest.c
TOBJ    = #stattest.o
TOBJ2   = rvstest.o
STOBJ	= sif.o
MSRC	= test3.c
MOBJ	= test3.o
TSRC4	= test4.c
TOBJ4	= test4.o
TSRC5   = test-tcpip.c
TOBJ5   = test-tcpip.o

#LIBS	= -lpthread -ldl
LIBS	= $(LIBAIF)
CLIBS	= $(LIBCIF)
SLIBS	= $(LIBSIF) -lpthread

RDEFS =
SDEFS = -DRSI_SOCKBASE
CDEFS = -DRVS_TEST
#DEFS = -Wall -O2 $(RDEFS)
#DEFS = $(RDEFS) -DRVS_AF_UNIX -DUSE_THREAD=1 -DLINUX -DTRACE_PACKET=1 -DAPPIFLOGPATH="\"/tmp/appif.log\""
#DEFS = $(RDEFS)  -D_DO_LOG_ -DUSE_THREAD=1 -DLINUX -DTRACE_PACKET=1 -DAPPIFLOGPATH="\"./appif.log\""
#DEFS = $(RDEFS) -DSOCK_SPLIT -DSOCK_SPLIT_DBG -D_DO_LOG_ -DUSE_THREAD=1 -DLINUX -DTRACE_PACKET=1 -DAPPIFLOGPATH="\"./appif.log\""
DEFS = $(RDEFS) -DSOCK_SPLIT -DSOCK_SPLIT_DBG -D_DO_LOG_ -DUSE_THREAD=1 -DLINUX  -DAPPIFLOGPATH="\"./appif.log\""
#INCS	= -I. -I../include
INCS	= -I. -I../tcpip/jni/inc -I../vpnc/jni/include


OBJS	= $(SRCS:.c=.o)
COBJS	= $(CSRCS:.c=.o)
SOBJS	= $(SSRCS:.c=.o) $(SMOBJ)


#CFLAGS	= -g -Wall -O0 -D_DO_LOG_ $(INCS) $(DEFS)
CFLAGS	= -g -Wall -O0 $(INCS) $(DEFS)

#all:	$(LIBAIF) $(LIBSIF) $(TESTP) $(CTESTP) $(STESTP) $(MTESTP)
all:	$(LIBCIF) $(LIBSIF) $(STATP) $(STESTP)
#all:	$(LIBCIF) $(LIBSIF) $(STESTP) $(TEST5_L) $(TEST5_R)

$(TEST5_L) : $(LIBS) $(TOBJ5)
	$(CC) $(CFLAGS) -o $(TEST5_L) $(TOBJ5) $(LIBS)

$(TEST5_R) : $(TSRC5)
	$(CC) $(CFLAGS) -o $(TEST5_R) $(TSRC5)

$(TESTP): $(TOBJ)
	$(CC) $(CFLAGS) -o $(TESTP) $(TOBJ)

$(STATP): $(CLIBS) $(TOBJ)
	$(CC) $(CFLAGS) -o $(STATP) $(TOBJ) $(CLIBS)

$(MTESTP): $(LIBS) $(MOBJ)
	$(CC) $(CFLAGS) -o $(MTESTP) $(MOBJ) $(LIBS)

$(TESTP4): $(LIBS) $(TOBJ4)
	$(CC) $(CFLAGS) -lpthread -o $(TESTP4) $(TOBJ4) $(LIBS)

$(STESTP): $(SLIBS) $(STOBJ)
	$(CC) $(CFLAGS) -o $(STESTP) $(STOBJ) $(SLIBS)

$(LIBAIF): $(OBJS) $(RROBJ)
	$(AR) rc $(LIBAIF) $(OBJS) $(RROBJ)
	$(RANLIB) $(LIBAIF)

$(LIBCIF): $(COBJS) $(RROBJ)
	$(AR) rc $(LIBCIF) $(COBJS) $(RROBJ)
	$(RANLIB) $(LIBCIF)

$(LIBSIF): $(SOBJS) $(RROBJ)
	$(AR) rc $(LIBSIF) $(SOBJS) $(RROBJ)
	$(RANLIB) $(LIBSIF)

$(RROBJ): $((RRSRC)
	$(CC) $(CFLAGS)	$(RRDEFS) -o $(RROBJ) -c $(RRSRC)

$(SMOBJ): $(SMSRC)
	$(CC) $(CFLAGS) $(SDEFS) -o $(SMOBJ) -c $(SMSRC)

$(TOBJ): $(TSRC)
	$(CC) $(CFLAGS) $(CDEFS) -o $(TOBJ) -c $(TSRC)

$(MOBJ): $(MSRC)
	$(CC) $(CFLAGS) $(CDEFS) -o $(MOBJ) -c $<

$(TOBJ4): $(TSRC4)
	$(CC) $(CFLAGS) $(CDEFS) -o $(TOBJ4) -c $<

$(TOBJ5): $(TSRC5)
	$(CC) $(CFLAGS) $(CDEFS) -o $(TOBJ5) -c $<

depend: $(SRCS) $(SSRCS)
	makedepend -f .depend $(INCS) $(DEFS) $(SRCS) $(SSRCS)
#	makedepend $(INCS) $(DEFS) $(SRCS) $(SSRCS)

clean:
	$(RM) -f $(CTESTP) $(STESTP) $(TESTP) $(LIBAIF) $(TOBJ) $(TOBJ2) $(OBJS) $(SOBJS) $(TEST5_L) $(TEST5_R) $(TOBJ5) *.bak *~

#include .depend

